/*
 * Copyright 2015-2019 Autoware Foundation. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <libyaml/libyaml.hpp>
#include <boost/filesystem.hpp>


Libyaml::Libyaml(string file){
    yaml_file_path = file;
}

bool Libyaml::load_file(){
    if (boost::filesystem::exists(yaml_file_path)== false){
        // boost::filesystem::create_directories(gpsdata_dir);
        YAML::Node conf = YAML::Load("");
        return  false;
    }else{
        conf = YAML::LoadFile(yaml_file_path);
    }
    return  true;
}

void Libyaml::save_file()
{
	    std::ofstream fout(yaml_file_path);
	    fout <<conf;
	    fout.close();
}

void Libyaml::set_origin_geo(double lat_o,double lon_o,double h_o)
{
        // localcartesian_h0: 40.64
        // localcartesian_lat0: 36.70261262
        // localcartesian_lon0: 117.14650666

	    conf["localcartesian_lat0"]=lat_o;
	    conf["localcartesian_lon0"]=lon_o;
	    conf["localcartesian_h0"]=h_o;
}
void Libyaml::get_origin_geo(double &lat_o,double &lon_o,double &h_o)
{
      if (conf["localcartesian_lat0"])
          lat_o = conf["localcartesian_lat0"].as<double>() ;

      if (conf["localcartesian_lon0"])
          lon_o = conf["localcartesian_lon0"].as<double>() ;

      if (conf["localcartesian_h0"])
          h_o = conf["localcartesian_h0"].as<double>() ;
}


